package com.yisen.dasan.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yisen.dasan.config.Auth;
import com.yisen.dasan.service.QuestionnaireService;
import com.yisen.dasan.util.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @AuthorList: LiuYiSen
 * @Date: 2020/10/21 11:27
 */
@RestController
@CrossOrigin
@RequestMapping("/questionnaire")
@Slf4j
public class QuestionnaireController {
    @Autowired
    QuestionnaireService questionnaireService;
    @PostMapping("/add")
    @Auth
    public ResultData add(@RequestBody JSONObject jsonObject, HttpServletRequest request){
        System.out.println(jsonObject);
        boolean b = questionnaireService.addForm(jsonObject, request);
        if(b)
            return new ResultData(true, 200, "添加成功！", jsonObject);
        return new ResultData(false, 200, "添加失败！", jsonObject);
    }
    @GetMapping("/addCount")
    public ResultData addCount(@RequestParam("formId") int formId){
        boolean b = questionnaireService.addCount(formId);
        if(b)
            return new ResultData(true, 200, "增加成功！", null);
        return new ResultData(false, 200, "增加失败！", null);
    }
}
